1. Field of the Invention
This invention relates in general to a computer operating systems, and more particularly to a method, apparatus and program storage device for providing light weight system calls to improve user mode performance.
2. Description of Related Art
A thread is a sequence of instructions. Multiple threads can be executed in parallel on many computer systems. Multithreading generally occurs by time slicing where a single processor switches between different threads or by multiprocessing where threads are executed on separate processors. Threads are similar to processes, but differ in the way that they share resources. Many modern operating systems directly support both time-sliced and multiprocessor threading with a process scheduler. The operating system kernel allows programmers to manipulate threads via the system call interface. Some implementations are called kernel threads or lightweight processes.
Operating systems generally implement threads in one of two ways: preemptive multithreading, or cooperative multithreading. Preemptive multithreading allows the operating system to determine when a context switch should occur. The term context simply refers to all the information that completely describes the process's current state of execution, e.g., the contents of the CPU registers, the program counter, the flags, etc. The process of saving the currently executing process's context, flushing the CPU, and loading the next process's context, is called a context switch. A context switch for a full-fledged, multithreaded process will obviously take a lot longer than a context switch for an individual thread within a process. So depending on the amount of hardware support for context switching and the type of context switch, a context switch can take a decent amount of time, thereby wasting a number of CPU cycles. Cutting back on context switches improves execution efficiency and reduces waste, as does the extensive use of multithreading since thread switches are usually faster than full-sized process switches.
Cooperative multithreading, on the other hand, relies on the threads themselves to relinquish control once they are at a stopping point. This can create problems if a thread is waiting for a resource to become available. The disadvantage to preemptive multithreading is that the system may make a context switch at an inappropriate time, causing priority inversion or other bad effects, which may be avoided by cooperative multithreading.
In multithreaded operating systems, all threads in a task share the same address space and are usually sharing large amounts of data. Context switching between two threads in the same task may take much less time than context switching between two threads in different tasks. After a context switch in a multithreaded system a new thread will be running, and perhaps a new task.
The kernel mode is a privileged mode in which only the kernel runs and which provides access to all memory locations and all other system resources. Context switches can occur only in kernel mode. Other programs, including applications, initially operate in user mode, but they can run portions of the kernel code via system calls. A system call is a request by an active process for a service performed by the kernel, such as input/output (I/O) or process creation.
Many current computer systems employ two privilege levels: (1) a most privileged level, or kernel-privilege level; and (2) a less privileged level, or application-program privilege level. The privilege level at which a process executes determines the total range or ranges of virtual memory that the process can access and the range of instructions within the total instruction set that can be executed by the processor on behalf of the process.
The privilege concept is used to prevent full access to computing resources by application programs. In order to obtain services that employ resources not directly available to application programs, application programs need to call operating system routines through the operating system interface. Operating system routines can promote the current privilege level to a higher privilege level to allow access to resources, to carry out a task requested by an application program, and then return control to the application program while simultaneously demoting the current privilege level. By restricting application-program access to computer resources, an operating system can maintain operating-system-only-accessible data structures for managing many different, concurrently executing programs, in the case of a single-processor computer, and, on a multi-processor computing system, many different concurrently executing application programs, a number of which execute in parallel. Privilege levels also prevent the processor from executing certain privileged instructions on behalf of application programs. For example, instructions that alter the contents of the process status register may be privileged, and may be executed by the processor only on behalf of an operating system routine running at a high privilege level. Generally, restricted instructions include instructions that manipulate the contents of control registers and special operating-system-specific data structures.
As an example of the use of privilege levels, consider concurrent execution of multiple processes, representing multiple application programs managed by the operating system in a single-processor computer system. The processor can execute instructions on behalf of only a single process at a time. The operating system may continuously schedule concurrently executing processes for brief periods of execution in order to provide, over time, a fraction of the total processing bandwidth of the computer system to each running application program. The operating system schedules a process for execution by removing the process-control block corresponding to the process from the process queue and writing the contents of various memory locations within the process-control block into various control registers and operating-system data structures. Similarly, the operating system removes a process from the executing state by storing the contents of control registers and operating-system data structures into the corresponding process-control block and re-queuing the process-control block to the process queue.
As described above, operating system routines are invoked through system calls, faults, traps, and interrupts during the course of execution of an application program. By maintaining the process queue in memory accessible only to routines executing at the highest privilege level, and by ensuring that some or all instructions required to store and retrieve data from control registers are instructions that have access to the highest privilege level, the architecture of the computing system ensures that only operating-system routines can schedule application processes for execution. Thus, an application program may not manipulate the process queue and control registers in order to monopolize system resources and prevent other application programs from obtaining computing resources for concurrent execution.
The operating system, as part of providing an application programming environment, provides both application-specific and application-sharable memory to application programs. An application program may store private data that the application wishes to be inaccessible to other application programs in private memory regions, and may exchange data with other application programs by storing date in sharable memory. Access to memory is controlled by the operating system through address mapping and access privileges associated with memory pages, each memory page generally comprising some fixed number of bytes. Because the instructions and operating-system data structures necessary for memory mapping and access privilege assignment include instructions and memory accessible only to routines executing at the highest privilege level, an application program executing at a lower privilege level may not remap memory or reassign access privileges in order to gain access to the private memory of other application programs.
Issuing system calls typically involves running a sequence of instructions to save the current context expecting for a process context switch. With the popularity of the Linux operating system, many controller applications have moved from kernel space in non-open source operating systems to user mode programs under Linux. With this move, calling privileged instructions become much more expensive than before because of the probability of a context switch needing to be made. Usually, an application program does not expect a context switch when calling privileged instructions. Nevertheless, system calls that perform the privileged instructions require that the processor context be saved and restored during a system call.
It can be seen then that there is a need for a method, apparatus and program storage device for providing light weight system calls to improve user mode performance.